package com.fho4565.core.cdgroup;

import com.fho4565.main.Utils;
import net.minecraft.commands.CommandSourceStack;
import org.jetbrains.annotations.NotNull;

import java.io.Serial;
import java.io.Serializable;
import java.util.Objects;

public class SingleCommand implements Serializable,Comparable<SingleCommand> {
    @Serial
    private static final long serialVersionUID = -695646970842157817L;
    private String name;
    private String command;
    private int executeTimes = 1;

    public SingleCommand(String name, String command) {
        this.name = name;
        this.command = command;
    }

    public SingleCommand(String name, String command, int executeTimes) {
        this.name = name;
        this.command = command;
        this.executeTimes = executeTimes;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCommand() {
        return command;
    }

    public void setCommand(String command) {
        this.command = command;
    }

    public int getExecuteTimes() {
        return executeTimes;
    }

    public void setExecuteTimes(int executeTimes) {
        this.executeTimes = executeTimes;
    }
    public void execute(CommandSourceStack stack) {
        if (executeTimes <= 0){
            return;
        }
        for (int i = 0; i < executeTimes; i++) {
            Utils.executeCommand(stack,command);
        }
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        SingleCommand another = (SingleCommand) obj;
        return name.equals(another.name);
    }
    @Override
    public int compareTo(@NotNull SingleCommand o) {
        return this.name.compareTo(o.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }
}
